DEF SEG Statement ---------------------------------------------------------------------------- Action Sets the current segment address for a subsequent PEEK function, BLOAD, BSAVE, Absolute routine, or POKE statement. Syntax DEF SEG -= address- Remarks For Absolute, BLOAD, BSAVE, PEEK, and POKE, address is used as the segment. The argument address is a numeric expression with an unsigned integer value between 0 and 65,535, inclusive. If you use a value outside this range, BASIC generates the error message Illegal function call. The previous segment is retained if an error occurs. If address is omitted, DGROUP is used. DEF SEG remains in effect until changed. To reset the current segment to the default data segment (DGROUP), use DEF SEG without any argument. Be sure to separate DEF and SEG with a space. Otherwise, BASIC interprets the statement to mean "assign a value to the variable DEFSEG." To set the current segment address to the address of data stored in far memory, you can use DEF SEG with the SSEG or VARSEG functions ( SSEG returns the current segment address of a string; VARSEG returns the current segment address of numeric data). For example, this statement sets the current address for a far string named a$ . DEF SEG = SSEG(a$) When using DEF SEG in OS-2 protected mode, any DEF SEG statement must refer only to a valid selector. The DEF SEG statement itself does not generate any memory references using the selector, nor does it attempt to validate the selector. If a misdirected DEF SEG statement causes your program to refer to an illegal memory address, the operating system may generate a protection exception, or BASIC may generate the error message Permission denied. The default DEF SEG segment always constitutes a valid memory reference. Use caution when altering this reference in protected mode. DEF SEG and Expanded Memory Arrays Do not use DEF SEG to set the segment of an expanded memory array. If you start QBX with the -Ea switch, any of these arrays may be stored in expanded memory. - Numeric arrays less than 16K in size. - Fixed-length string arrays less than 16K in size. - User-defined-type arrays less than 16K in size. If you want to use DEF SEG to set the segment of an array, first start QBX without the -Ea switch. (Without the -Ea switch, no arrays are stored in expanded memory.) For more information on using expanded memory, see "Memory Management for QBX" in Getting Started. BASICA In this version of BASIC, the CALL and CALLS statements do not use the segment address set by DEF SEG. See Also SADD; SSEG; VARPTR, VARSEG Example The following example uses DEF SEG, PEEK, and POKE to turn the Caps Lock key on and off. This program contains hardware-specific instructions. It works correctly on IBM PC, XT, and AT computers. DECLARE SUB CapsOn () DECLARE SUB CapsOff () DECLARE SUB PrntMsg (R%, C%, M$) CLS CapsOn PrntMsg 24, 1, "" LOCATE 12, 10 LINE INPUT "Enter a string (all characters are caps). ", S$ CapsOff PrntMsg 24, 1, " " PrntMsg 25, 1, "Press any key to continue..." DO WHILE INKEY$ = "". LOOP CLS END SUB CapsOff STATIC' Turn the Caps Lock key off. DEF SEG = 0' Set segment to low memory. POKE &H417, PEEK(&H417) AND &HBF' Turn off bit 6 of &H0417. DEF SEG ' Restore segment. END SUB SUB CapsOn STATIC' Turn Caps Lock on. DEF SEG = 0' Set segment to low memory. POKE &H417, PEEK(&H417) OR &H40' Turn on bit 6 of &H0417. DEF SEG ' Restore segment. END SUB SUB PrntMsg (Row%, Col%, Message$) STATIC ' Print message at Row%, Col% without changing cursor. CurRow% = CSRLIN. CurCol% = POS(0)' Save cursor position. LOCATE Row%, Col%. PRINT Message$; ' Restore cursor. LOCATE CurRow%, CurCol% END SUB